package com.xxzb.pack0822.多线程.守护线程;

public class 守护线程 {
    public static void main(String[] args) {
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println(Thread.currentThread().getName()+":"+i);
                }
            }
        },"t1");
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println(Thread.currentThread().getName()+":"+i);
                }
            }
        },"t2");
        Thread t3=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println(Thread.currentThread().getName()+":"+i);
                }
            }
        },"t3");
        t3.setDaemon(true);//设置t3为守护线程,守护线程最后一个结束的时候，其他线程执行完了，守护线程不管执行了多少都强制结束
        t1.start();
        t2.start();
        t3.start();
    }
}
